<template>
  <div class="xtx-confirm" :class="{ fade: isFade }">
    <div class="wrapper" :class="{ fade: isFade }">
      <div class="header">
        <h3>{{ props.title }}</h3>
        <a href="JavaScript:;" @click="props.cancel()" class="iconfont icon-close-new"></a>
      </div>
      <div class="body">
        <i class="iconfont icon-warning"></i>
        <span>{{ props.text }}</span>
      </div>
      <div class="footer">
        <xtx-button @click="props.cancel()" size="mini" type="gray">取消</xtx-button>
        <xtx-button @click="props.submit()" size="mini" type="primary">确认</xtx-button>
      </div>
    </div>
  </div>
</template>
<script setup>
import XtxButton from './xtx-button.vue'
import { defineProps, onMounted, ref } from 'vue'
const props = defineProps({
  title: {
    type: String,
    default: '温馨提示'
  },
  text: {
    type: String,
    default: '您确认从购物车删除该商品吗？'
  },
  submit: {
    type: Function
  },
  cancel: {
    type: Function
  }
})
// 构建一个简单动画效果
// 遮挡层 .xtx-confirm   background: rgba(0,0,0,0)--》 background: rgba(0,0,0,.5);
// 内容  .wrapper  transform: translate(-50%, -60%); opacity: 0; ===》 transform: translate(-50%,-50%)；opacity: 1;
// 通过fade类来控制
const isFade = ref(false)
onMounted(() => {
  isFade.value = true
})
</script>
<style scoped lang="less">
.xtx-confirm {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  z-index: 8888;
  background: rgba(0, 0, 0, 0);

  &.fade {
    transition: all 0.4s;
    background: rgba(0, 0, 0, .5);
  }

  .wrapper {
    width: 400px;
    background: #fff;
    border-radius: 4px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -60%);
    opacity: 0;

    &.fade {
      transition: all 0.4s;
      transform: translate(-50%, -50%);
      opacity: 1;
    }

    .header,
    .footer {
      height: 50px;
      line-height: 50px;
      padding: 0 20px;
    }

    .body {
      padding: 20px 40px;
      font-size: 16px;

      .icon-warning {
        color: @priceColor;
        margin-right: 3px;
        font-size: 16px;
      }
    }

    .footer {
      text-align: right;

      .xtx-button {
        margin-left: 20px;
      }
    }

    .header {
      position: relative;

      h3 {
        font-weight: normal;
        font-size: 18px;
      }

      a {
        position: absolute;
        right: 15px;
        top: 15px;
        font-size: 20px;
        width: 20px;
        height: 20px;
        line-height: 20px;
        text-align: center;
        color: #999;

        &:hover {
          color: #666;
        }
      }
    }
  }
}
</style>